package main 

import (
	"fmt"
	"strconv"
	"strings"
)
//go 字符串相关函数
func main(){

	var str string="china"
	fmt.Println("str len=",len(str))

	str1:="china 中国"

	//将字符串转换为切片
	str2:=[]rune(str1)
	for i:=0;i<len(str2);i++{
		fmt.Printf("%c\n",str2[i])
	}

	n,err:=strconv.Atoi("12345")
	if err!=nil{
		fmt.Println("error =",err)
	}else{
		fmt.Println("ok =",n)
	}

	str3:=strconv.Itoa(123)

	fmt.Printf("str=%v,str=%T\n",str3,str3)

	//字符串转换为byte切片
	var bytes = []byte("hello,go")
	fmt.Println("bytes=",bytes)

	str = string(bytes)
	fmt.Println("str=",str)

	//切片转换为字符串
	str = string([]byte{97,98,99})
	fmt.Println("str=",str)

	//10进制123转换为2进制字符串
	str = strconv.FormatInt(123,2)
	fmt.Println("str=",str)

	b:=strings.Contains("china","na")
	fmt.Println("b=",b)

	num:=strings.Count("chinaa","a")
	fmt.Println("num=",num)

	//判断字符串是否相等  不区分大小写
	b = strings.EqualFold("abc","Abc")
	fmt.Println("abc==Abc?",b)

	index:=strings.Index("china","n")
	fmt.Println("index=",index)

	index = strings.LastIndex("go go hello","go")
	fmt.Println("LastIndex=",index)

	//https://studygolang.com/pkgdoc
	str = strings.Replace("go go hello","go","php",-1)
	fmt.Println("replace=",str)

	strArr:=strings.Split("hello,go,php",",")
	for i:=0;i<len(strArr);i++{
		fmt.Println("strArr=",strArr[i])
	}

	str = "hello"
	str = strings.ToUpper(str)
	fmt.Println("str=",str)
	str = strings.ToLower(str)
	fmt.Println("str=",str)

	str = strings.TrimSpace("   china   klsd   ")
	fmt.Printf("str trim splace = %q\n",str)

	str = strings.Trim("! china !"," !")
	fmt.Println("trim=",str)

	b = strings.HasPrefix("fpt://ksfsd","fpt")
	fmt.Println("b=",b)
	b = strings.HasSuffix("aggds.jpg","jpg")
	fmt.Println("b=",b)
}